home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Corrida / dragracer.swf / scripts / %3Cdefault package%3E / FPushButtonSymbol.as < prev    next >
Encoding:
Text File  |  2005-10-06  |  8.6 KB  |  309 lines

  1. function FPushButtonClass()
  2. {
  3.    this.init();
  4. }
  5. FPushButtonClass.prototype = new FUIComponentClass();
  6. Object.registerClass("FPushButtonSymbol",FPushButtonClass);
  7. FPushButtonClass.prototype.init = function()
  8. {
  9.    var _loc1_ = this;
  10.    super.setSize(_loc1_._width,_loc1_._height);
  11.    _loc1_.boundingBox_mc.unloadMovie();
  12.    _loc1_.attachMovie("fpb_states","fpbState_mc",1);
  13.    _loc1_.attachMovie("FLabelSymbol","fLabel_mc",2);
  14.    _loc1_.attachMovie("fpb_hitArea","fpb_hitArea_mc",3);
  15.    super.init();
  16.    _loc1_.btnState = false;
  17.    _loc1_.setClickHandler(_loc1_.clickHandler);
  18.    _loc1_._xscale = 100;
  19.    _loc1_._yscale = 100;
  20.    _loc1_.setSize(_loc1_.width,_loc1_.height);
  21.    if(_loc1_.label != undefined)
  22.    {
  23.       _loc1_.setLabel(_loc1_.label);
  24.    }
  25.    _loc1_.ROLE_SYSTEM_PUSHBUTTON = 43;
  26.    _loc1_.STATE_SYSTEM_PRESSED = 8;
  27.    _loc1_.EVENT_OBJECT_STATECHANGE = 32778;
  28.    _loc1_.EVENT_OBJECT_NAMECHANGE = 32780;
  29.    _loc1_._accImpl.master = _loc1_;
  30.    _loc1_._accImpl.stub = false;
  31.    _loc1_._accImpl.get_accRole = _loc1_.get_accRole;
  32.    _loc1_._accImpl.get_accName = _loc1_.get_accName;
  33.    _loc1_._accImpl.get_accState = _loc1_.get_accState;
  34.    _loc1_._accImpl.get_accDefaultAction = _loc1_.get_accDefaultAction;
  35.    _loc1_._accImpl.accDoDefaultAction = _loc1_.accDoDefaultAction;
  36. };
  37. FPushButtonClass.prototype.setHitArea = function(w, h)
  38. {
  39.    var _loc1_ = this.fpb_hitArea_mc;
  40.    this.hitArea = _loc1_;
  41.    _loc1_._visible = false;
  42.    _loc1_._width = w;
  43.    _loc1_._height = arguments.length <= 1 ? _loc1_._height : h;
  44. };
  45. FPushButtonClass.prototype.setSize = function(w, h)
  46. {
  47.    var _loc1_ = this;
  48.    var _loc2_ = w;
  49.    var _loc3_ = h;
  50.    _loc2_ = _loc2_ >= 6 ? _loc2_ : 6;
  51.    if(arguments.length > 1)
  52.    {
  53.       if(_loc3_ < 6)
  54.       {
  55.          _loc3_ = 6;
  56.       }
  57.    }
  58.    super.setSize(_loc2_,_loc3_);
  59.    _loc1_.setLabel(_loc1_.getLabel());
  60.    _loc1_.arrangeLabel();
  61.    _loc1_.setHitArea(_loc2_,_loc3_);
  62.    _loc1_.boundingBox_mc._width = _loc2_;
  63.    _loc1_.boundingBox_mc._height = _loc3_;
  64.    _loc1_.drawFrame();
  65.    if(_loc1_.focused)
  66.    {
  67.       super.myOnSetFocus();
  68.    }
  69.    _loc1_.initContentPos("fLabel_mc");
  70. };
  71. FPushButtonClass.prototype.arrangeLabel = function()
  72. {
  73.    var _loc3_ = this;
  74.    var _loc1_ = _loc3_.fLabel_mc;
  75.    var h = _loc3_.height;
  76.    var w = _loc3_.width - 2;
  77.    var _loc2_ = 1;
  78.    _loc3_.fLabel_mc.setSize(w - _loc2_ * 4);
  79.    _loc1_._x = _loc2_ * 3;
  80.    _loc1_._y = h / 2 - _loc1_._height / 2;
  81. };
  82. FPushButtonClass.prototype.getLabel = function()
  83. {
  84.    return this.fLabel_mc.labelField.text;
  85. };
  86. FPushButtonClass.prototype.setLabel = function(label)
  87. {
  88.    var _loc1_ = this;
  89.    _loc1_.fLabel_mc.setLabel(label);
  90.    _loc1_.txtFormat();
  91.    _loc1_.arrangeLabel();
  92.    if(Accessibility.isActive())
  93.    {
  94.       Accessibility.sendEvent(_loc1_,0,_loc1_.EVENT_OBJECT_NAMECHANGE);
  95.    }
  96. };
  97. FPushButtonClass.prototype.getEnabled = function()
  98. {
  99.    return this.enabled;
  100. };
  101. FPushButtonClass.prototype.setEnabled = function(enable)
  102. {
  103.    var _loc1_ = this;
  104.    if(enable || enable == undefined)
  105.    {
  106.       _loc1_.gotoFrame(1);
  107.       _loc1_.drawFrame();
  108.       _loc1_.flabel_mc.setEnabled(true);
  109.       _loc1_.enabled = true;
  110.       super.setEnabled(true);
  111.    }
  112.    else
  113.    {
  114.       _loc1_.gotoFrame(4);
  115.       _loc1_.drawFrame();
  116.       _loc1_.flabel_mc.setEnabled(false);
  117.       _loc1_.enabled = false;
  118.       super.setEnabled(false);
  119.    }
  120. };
  121. FPushButtonClass.prototype.txtFormat = function()
  122. {
  123.    var _loc1_ = this;
  124.    var _loc2_ = _loc1_.textStyle;
  125.    var _loc3_ = _loc1_.styleTable;
  126.    _loc2_.align = _loc3_.textAlign.value != undefined ? undefined : (_loc2_.align = "center");
  127.    _loc2_.leftMargin = _loc3_.textLeftMargin.value != undefined ? undefined : (_loc2_.leftMargin = 1);
  128.    _loc2_.rightMargin = _loc3_.textRightMargin.value != undefined ? undefined : (_loc2_.rightMargin = 1);
  129.    if(_loc1_.fLabel_mc._height > _loc1_.height)
  130.    {
  131.       super.setSize(_loc1_.width,_loc1_.fLabel_mc._height);
  132.    }
  133.    else
  134.    {
  135.       super.setSize(_loc1_.width,_loc1_.height);
  136.    }
  137.    _loc1_.fLabel_mc.labelField.setTextFormat(_loc1_.textStyle);
  138.    _loc1_.setEnabled(_loc1_.enable);
  139. };
  140. FPushButtonClass.prototype.drawFrame = function()
  141. {
  142.    var _loc3_ = this;
  143.    var _loc2_ = 1;
  144.    var x1 = 0;
  145.    var y1 = 0;
  146.    var x2 = _loc3_.width;
  147.    var y2 = _loc3_.height;
  148.    var mc_array = ["up_mc","over_mc","down_mc","disabled_mc"];
  149.    var frame = mc_array[_loc3_.fpbState_mc._currentframe - 1];
  150.    var mc = "frame";
  151.    var _loc1_ = 0;
  152.    while(_loc1_ < 6)
  153.    {
  154.       x1 += _loc1_ % 2 * _loc2_;
  155.       y1 += _loc1_ % 2 * _loc2_;
  156.       x2 -= (_loc1_ + 1) % 2 * _loc2_;
  157.       y2 -= (_loc1_ + 1) % 2 * _loc2_;
  158.       var w = Math.abs(x1 - x2) + 2 * _loc2_;
  159.       var h = Math.abs(y1 - y2) + 2 * _loc2_;
  160.       _loc3_.fpbState_mc[frame][mc + _loc1_]._width = w;
  161.       _loc3_.fpbState_mc[frame][mc + _loc1_]._height = h;
  162.       _loc3_.fpbState_mc[frame][mc + _loc1_]._x = x1 - _loc2_;
  163.       _loc3_.fpbState_mc[frame][mc + _loc1_]._y = y1 - _loc2_;
  164.       _loc1_ = _loc1_ + 1;
  165.    }
  166. };
  167. FPushButtonClass.prototype.setClickHandler = function(chng, obj)
  168. {
  169.    var _loc1_ = this;
  170.    _loc1_.handlerObj = arguments.length >= 2 ? obj : _loc1_._parent;
  171.    _loc1_.clickHandler = chng;
  172. };
  173. FPushButtonClass.prototype.executeCallBack = function()
  174. {
  175.    var _loc1_ = this;
  176.    _loc1_.handlerObj[_loc1_.clickHandler](_loc1_);
  177. };
  178. FPushButtonClass.prototype.initContentPos = function(mc)
  179. {
  180.    var _loc1_ = this;
  181.    _loc1_.incrVal = 1;
  182.    _loc1_.initx = _loc1_[mc]._x - _loc1_.getBtnState() * _loc1_.incrVal;
  183.    _loc1_.inity = _loc1_[mc]._y - _loc1_.getBtnState() * _loc1_.incrVal;
  184.    _loc1_.togx = _loc1_.initx + _loc1_.incrVal;
  185.    _loc1_.togy = _loc1_.inity + _loc1_.incrVal;
  186. };
  187. FPushButtonClass.prototype.setBtnState = function(state)
  188. {
  189.    var _loc1_ = this;
  190.    _loc1_.btnState = state;
  191.    if(state)
  192.    {
  193.       _loc1_.fLabel_mc._x = _loc1_.togx;
  194.       _loc1_.fLabel_mc._y = _loc1_.togy;
  195.    }
  196.    else
  197.    {
  198.       _loc1_.fLabel_mc._x = _loc1_.initx;
  199.       _loc1_.fLabel_mc._y = _loc1_.inity;
  200.    }
  201. };
  202. FPushButtonClass.prototype.getBtnState = function()
  203. {
  204.    return this.btnState;
  205. };
  206. FPushButtonClass.prototype.myOnSetFocus = function()
  207. {
  208.    this.focused = true;
  209.    super.myOnSetFocus();
  210. };
  211. FPushButtonClass.prototype.onPress = function()
  212. {
  213.    var _loc1_ = this;
  214.    _loc1_.pressFocus();
  215.    _loc1_.fpbState_mc.gotoAndStop(3);
  216.    _loc1_.drawFrame();
  217.    _loc1_.setBtnState(true);
  218.    if(Accessibility.isActive())
  219.    {
  220.       Accessibility.sendEvent(_loc1_,0,_loc1_.EVENT_OBJECT_STATECHANGE,true);
  221.    }
  222. };
  223. FPushButtonClass.prototype.onRelease = function()
  224. {
  225.    var _loc1_ = this;
  226.    _loc1_.fpbState_mc.gotoAndStop(2);
  227.    _loc1_.drawFrame();
  228.    _loc1_.executeCallBack();
  229.    _loc1_.setBtnState(false);
  230.    if(Accessibility.isActive())
  231.    {
  232.       Accessibility.sendEvent(_loc1_,0,_loc1_.EVENT_OBJECT_STATECHANGE,true);
  233.    }
  234. };
  235. FPushButtonClass.prototype.onRollOver = function()
  236. {
  237.    this.fpbState_mc.gotoAndStop(2);
  238.    this.drawFrame();
  239. };
  240. FPushButtonClass.prototype.onRollOut = function()
  241. {
  242.    this.fpbState_mc.gotoAndStop(1);
  243.    this.drawFrame();
  244. };
  245. FPushButtonClass.prototype.onReleaseOutside = function()
  246. {
  247.    var _loc1_ = this;
  248.    _loc1_.setBtnState(false);
  249.    _loc1_.fpbState_mc.gotoAndStop(1);
  250.    _loc1_.drawFrame();
  251. };
  252. FPushButtonClass.prototype.onDragOut = function()
  253. {
  254.    var _loc1_ = this;
  255.    _loc1_.setBtnState(false);
  256.    _loc1_.fpbState_mc.gotoAndStop(1);
  257.    _loc1_.drawFrame();
  258. };
  259. FPushButtonClass.prototype.onDragOver = function()
  260. {
  261.    var _loc1_ = this;
  262.    _loc1_.setBtnState(true);
  263.    _loc1_.fpbState_mc.gotoAndStop(3);
  264.    _loc1_.drawFrame();
  265. };
  266. FPushButtonClass.prototype.myOnKeyDown = function()
  267. {
  268.    var _loc1_ = this;
  269.    if(Key.getCode() == 32 && _loc1_.pressOnce == undefined)
  270.    {
  271.       _loc1_.onPress();
  272.       _loc1_.pressOnce = 1;
  273.    }
  274. };
  275. FPushButtonClass.prototype.myOnKeyUp = function()
  276. {
  277.    if(Key.getCode() == 32)
  278.    {
  279.       this.onRelease();
  280.       this.pressOnce = undefined;
  281.    }
  282. };
  283. FPushButtonClass.prototype.get_accRole = function(childId)
  284. {
  285.    return this.master.ROLE_SYSTEM_PUSHBUTTON;
  286. };
  287. FPushButtonClass.prototype.get_accName = function(childId)
  288. {
  289.    return this.master.getLabel();
  290. };
  291. FPushButtonClass.prototype.get_accState = function(childId)
  292. {
  293.    var _loc1_ = this;
  294.    if(_loc1_.pressOnce)
  295.    {
  296.       return _loc1_.master.STATE_SYSTEM_PRESSED;
  297.    }
  298.    return _loc1_.master.STATE_SYSTEM_DEFAULT;
  299. };
  300. FPushButtonClass.prototype.get_accDefaultAction = function(childId)
  301. {
  302.    return "Press";
  303. };
  304. FPushButtonClass.prototype.accDoDefaultAction = function(childId)
  305. {
  306.    this.master.onPress();
  307.    this.master.onRelease();
  308. };
  309.